Skip to content

Conversation

@tataruty
Copy link
Contributor

@tataruty tataruty commented Oct 17, 2025

Proposed changes

Problem: As a user of NGF
I want to have the ability to configure the log format of NGINX's access and error logs
So that I can easily collect logs from NGINX in my logging platform.

Solution: Adding accessLog.Disabled and accessLog.Format fields to nginx-proxy CRD, also adding default values for them

Testing:
Tested with custom format:

kubectl patch nginxproxy nginx-gateway-proxy-config -n nginx-gateway --type merge -p '{"spec":{"logging":{"errorLevel":"debug","accessLog":{"format":"$remote_addr - [$time_local] \"$request\" $status $body_bytes_sent"}}}}'

result:
config uses /dev/stdout and default format name:
image

work:
image

Tested with turning logs OFF:

kubectl patch nginxproxy nginx-gateway-proxy-config -n nginx-gateway --type merge -p '{"spec":{"logging":{"errorLevel":"debug","accessLog":{"disabled":true}}}}'
image

result:
config has only off without custom log_format:
image

Closes #1200

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Add ability to configure access log format or turn logging off

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.14%. Comparing base (96032ac) to head (7022c4f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4102      +/-   ##
==========================================
+ Coverage   86.09%   86.14%   +0.04%     
==========================================
  Files         131      131              
  Lines       14171    14193      +22     
  Branches       35       35              
==========================================
+ Hits        12200    12226      +26     
+ Misses       1767     1764       -3     
+ Partials      204      203       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from 0923130 to 3d18022 Compare October 24, 2025 18:28
@tataruty tataruty marked this pull request as ready for review October 24, 2025 18:30
@tataruty tataruty requested a review from a team as a code owner October 24, 2025 18:30
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch 3 times, most recently from 253e3be to b68f73f Compare November 3, 2025 11:17
@tataruty tataruty requested a review from ciarams87 November 3, 2025 12:58
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from b68f73f to 74bb187 Compare November 4, 2025 11:16
Copy link
Contributor

@ciarams87 ciarams87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API definition feels a bit confusing - as we are only supporting a single log format and a single path, we should simplify the API.

The two-level structure (NginxLogFormat + NginxAccessLog) creates indirection:

  • Users define a format with a name
  • Then reference that name in accessLog
  • This can lead to misconfiguration (mismatched names)
  • Both LogFormat AND AccessLog must be set for anything to work

I think we can remove the NginxLogFormat type completely and change the Format field in NginxAccessLog to specify the format string directly. We don't need to provide a mechanism for the user to specify the name of the log format, we can define that as an internal string.

Something like:

type NginxAccessLog struct {
    // Disabled turns off access logging when set to true.
    // +optional
    Disabled *bool `json:"disabled,omitempty"`
    
    // Format specifies the custom log format string.
    // If not specified, NGINX default 'combined' format is used.
    // See https://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
    // +optional
    Format *string `json:"format,omitempty"`
}

Later, if we decide to support different path types (e.g. syslog) we can extend this type to add the path field.

Then, if the access log format is set the template renders something like:

log_format ngf_default '<user-format>';
access_log /dev/stdout ngf_default;

And if it's disabled,

access_log off;

Otherwise we can omit the directive, and NGINX will use the default /dev/stdout combined (same behaviour as we have currently)

Does that make sense?

@github-project-automation github-project-automation bot moved this from 🆕 New to 🏗 In Progress in NGINX Gateway Fabric Nov 5, 2025
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from 74bb187 to aadd4f6 Compare November 6, 2025 11:11
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from aadd4f6 to f768d25 Compare November 6, 2025 16:59
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from f768d25 to a0ba554 Compare November 7, 2025 09:40
@tataruty tataruty force-pushed the enhancement/configurabe_dataplane_log_format branch from 865c794 to 85cdb55 Compare November 7, 2025 10:35
@ciarams87
Copy link
Contributor

Looks pretty good, good job!

We should also add the new fields to the Helm schema https://github.com/nginx/nginx-gateway-fabric/blob/main/charts/nginx-gateway-fabric/values.yaml#L451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request release-notes

Projects

Status: 🏗 In Progress

Development

Successfully merging this pull request may close these issues.

Configurable Data Plane Log Format

6 participants